/**
 * 
 */
package app.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import org.apache.commons.lang.StringUtils;

import app.constants.CollabVizConstants;
import app.exceptions.CollabVizException;

/**
 * @author poornima
 * 
 */
public class PropertyLoaderUtil {

	private static Properties prop;

	public PropertyLoaderUtil(String configFilePath) throws CollabVizException {
		loadPropConfigFile(configFilePath);
	}

	private void loadPropConfigFile(String filePath) throws CollabVizException {
		if (filePath == null
				|| org.apache.commons.lang.StringUtils.isEmpty(filePath)) {
			throw new CollabVizException(CollabVizConstants.FILE_IO_ERROR);
		}
		prop = new Properties();
		try {
			prop.load(new FileInputStream(new File(filePath)));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			throw new CollabVizException(
					CollabVizConstants.FILE_NOT_FOUND_ERROR);
		} catch (IOException e) {
			e.printStackTrace();
			throw new CollabVizException(CollabVizConstants.FILE_IO_ERROR);
		}
	}

	public static String getProp(String key) throws CollabVizException {
		String result = null;
		if (key == null || StringUtils.isEmpty(key)) {
			throw new CollabVizException(
					CollabVizConstants.INCOMING_PARAM_EMPTY_ERROR);
		}
		if (prop != null) {
			result = (String) prop.get(key);
		}
		return result;
	}
}
